

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 实现效果 下拉刷新上拉加载 1. 准备环境 Android Studio 2020.3.1(1) 给项目安装 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01布局组件(2) 在 dependencies依赖中添加一行 1implementation &amp;#x27;androidx.swiperefreshlayout">
<meta property="og:type" content="article">
<meta property="og:title" content="Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView">
<meta property="og:url" content="http://example.com/2021/11/21/Android%20_%20%E5%90%8C%E6%97%B6%E5%AE%9E%E7%8E%B0%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0%E5%92%8C%E4%B8%8B%E6%8B%89%E5%8A%A0%E8%BD%BD%20_%20%E5%9F%BA%E4%BA%8ESwipeRefreshLayout%20%E5%92%8C%20ListView/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 实现效果 下拉刷新上拉加载 1. 准备环境 Android Studio 2020.3.1(1) 给项目安装 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01布局组件(2) 在 dependencies依赖中添加一行 1implementation &amp;#x27;androidx.swiperefreshlayout">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/dc19c7c695a64d39b985b3e99916d5df.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e9b0341fb9204ee3b7e11d47b8bdc34b.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f685f921e0c346ed92af658bc3f845b3.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b22b9b8755ed419e9ccb15d934a7f2cc.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2e4fac3238134946b4270a48da81aa47.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/9f2a3d2a88ea4483a6bfaaabb9e9c560.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b7b0b89ff6c44d4680a816781688a6b8.png">
<meta property="article:published_time" content="2021-11-21T12:57:53.000Z">
<meta property="article:modified_time" content="2022-08-22T15:42:13.367Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Android">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/dc19c7c695a64d39b985b3e99916d5df.gif#pic_center">
  
  
  
  <title>Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-11-21 20:57" pubdate>
          2021年11月21日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          56 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="实现效果"><a href="#实现效果" class="headerlink" title="实现效果"></a>实现效果</h1><hr>
<p><code>下拉刷新</code><br><img src="https://img-blog.csdnimg.cn/dc19c7c695a64d39b985b3e99916d5df.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><code>上拉加载</code><br><img src="https://img-blog.csdnimg.cn/e9b0341fb9204ee3b7e11d47b8bdc34b.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="1-准备环境"><a href="#1-准备环境" class="headerlink" title="1. 准备环境"></a>1. 准备环境</h1><hr>
<p>Android Studio 2020.3.1<br><img src="https://img-blog.csdnimg.cn/f685f921e0c346ed92af658bc3f845b3.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>(1) 给项目安装 <code>androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01</code>布局组件<br><img src="https://img-blog.csdnimg.cn/b22b9b8755ed419e9ccb15d934a7f2cc.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>(2) 在 dependencies依赖中添加一行</p>
<figure class="highlight gradle"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs gradle">implementation <span class="hljs-string">&#x27;androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01&#x27;</span><br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/2e4fac3238134946b4270a48da81aa47.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述">(3) 点击 Sync 同步，完成安装<br><img src="https://img-blog.csdnimg.cn/9f2a3d2a88ea4483a6bfaaabb9e9c560.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述">笔者使用的是1.1.0 beta01版本，只要保证在这个版本之上应该都适用，更多关于这个布局的使用，请参考官方API <a target="_blank" rel="noopener" href="https://developer.android.google.cn/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout?hl=en">Android开发文档</a>，</p>
<h1 id="2-布局"><a href="#2-布局" class="headerlink" title="2. 布局"></a>2. 布局</h1><hr>
<h2 id="2-1-foot-view"><a href="#2-1-foot-view" class="headerlink" title="2.1 foot_view"></a>2.1 foot_view</h2><p><code>foot_view</code> 用于显示上拉加载时，出现的画面提示，到时候会添加到列表框的底部</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;utf-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">LinearLayout</span> <span class="hljs-attr">xmlns:android</span>=<span class="hljs-string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">android:orientation</span>=<span class="hljs-string">&quot;vertical&quot;</span></span><br><span class="hljs-tag">    &gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">TextView</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:id</span>=<span class="hljs-string">&quot;@+id/foot_view_tv&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:gravity</span>=<span class="hljs-string">&quot;center&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:text</span>=<span class="hljs-string">&quot;加载更多...&quot;</span></span><br><span class="hljs-tag">         /&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">LinearLayout</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>ftoo_view.xml 布局的效果图：<br><img src="https://img-blog.csdnimg.cn/b7b0b89ff6c44d4680a816781688a6b8.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-2-activity-main"><a href="#2-2-activity-main" class="headerlink" title="2.2 activity_main"></a>2.2 activity_main</h2><p><code>activity_main.xml</code> 应用主要的布局 ，在 SwipeRefreshLayout布局里嵌套了一个 ListView</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;utf-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">LinearLayout</span> <span class="hljs-attr">xmlns:android</span>=<span class="hljs-string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">xmlns:tools</span>=<span class="hljs-string">&quot;http://schemas.android.com/tools&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">    <span class="hljs-attr">tools:context</span>=<span class="hljs-string">&quot;.MainActivity&quot;</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">androidx.swiperefreshlayout.widget.SwipeRefreshLayout</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:id</span>=<span class="hljs-string">&quot;@+id/refresh&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">        &gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">ListView</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:id</span>=<span class="hljs-string">&quot;@+id/listview&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">        <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span></span><br><span class="hljs-tag">         /&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">androidx.swiperefreshlayout.widget.SwipeRefreshLayout</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">LinearLayout</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h1 id="3-代码实现"><a href="#3-代码实现" class="headerlink" title="3.代码实现"></a>3.代码实现</h1><hr>
<h2 id="3-1-全局变量"><a href="#3-1-全局变量" class="headerlink" title="3.1 全局变量"></a>3.1 全局变量</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">AppCompatActivity</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">SwipeRefreshLayout</span>.OnRefreshListener, AbsListView.OnScrollListener&#123;<br>    ArrayList&lt;String&gt; list_all;             <span class="hljs-comment">// 存储列表所有的测试数据</span><br>    ArrayList&lt;String&gt; list_lv;              <span class="hljs-comment">// 存储列表当前的数据</span><br>    ArrayAdapter&lt;String&gt; adapter;           <span class="hljs-comment">// ListView的适配器对象</span><br>    SwipeRefreshLayout refreshLayout;       <span class="hljs-comment">// 主界面刷新布局的对象</span><br>    ListView lv;                            <span class="hljs-comment">// 主界面列表对象</span><br>    View foot;                              <span class="hljs-comment">// 上拉加载底部的视图</span><br>    <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">MAX_PAGE</span> <span class="hljs-operator">=</span> <span class="hljs-number">5</span>;                 <span class="hljs-comment">// 最多的页数</span><br>    <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">PER_PAGE</span> <span class="hljs-operator">=</span> <span class="hljs-number">15</span>;                <span class="hljs-comment">// 每页的数据个数</span><br>    <span class="hljs-type">int</span> <span class="hljs-variable">page</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;                           <span class="hljs-comment">// 当前页数</span><br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="3-2-OnCreate"><a href="#3-2-OnCreate" class="headerlink" title="3.2 OnCreate"></a>3.2 OnCreate</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onCreate</span><span class="hljs-params">(Bundle savedInstanceState)</span> &#123;<br>        <span class="hljs-built_in">super</span>.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);<br><br>        <span class="hljs-comment">// 1. 获取组件</span><br>        lv = findViewById(R.id.listview);<br>        refreshLayout = findViewById(R.id.refresh);<br><br>        <span class="hljs-comment">// 2. 产生列表框测试的数据</span><br>        list_all = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; PER_PAGE * MAX_PAGE; i++)<br>            list_all.add(String.format(<span class="hljs-string">&quot;Botton:%d&quot;</span>, i));<br>        list_lv = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;(list_all.subList(<span class="hljs-number">0</span>, PER_PAGE));<br><br>        <span class="hljs-comment">// 3. 设置 适配器 以及 视图</span><br>        adapter = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayAdapter</span>&lt;&gt;(<span class="hljs-built_in">this</span>, android.R.layout.simple_list_item_1, list_lv);<br>        foot = LayoutInflater.from(<span class="hljs-built_in">this</span>).inflate(R.layout.foot_view,<span class="hljs-literal">null</span>);<br>        lv.setAdapter(adapter);<br><br>        <span class="hljs-comment">// 4. 设置监听事件</span><br>        lv.setOnScrollListener(<span class="hljs-built_in">this</span>);               <span class="hljs-comment">// 下拉刷新</span><br>        refreshLayout.setOnRefreshListener(<span class="hljs-built_in">this</span>);   <span class="hljs-comment">// 上拉加载</span><br>    &#125;<br></code></pre></td></tr></table></figure>

<h2 id="3-3-自定义的showInfo方法"><a href="#3-3-自定义的showInfo方法" class="headerlink" title="3.3 自定义的showInfo方法"></a>3.3 自定义的showInfo方法</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">showPageInfo</span><span class="hljs-params">()</span>&#123;<br>      Toast.makeText(MainActivity.<span class="hljs-built_in">this</span>, String.format(<span class="hljs-string">&quot;当前是第%d页&quot;</span>,page), Toast.LENGTH_SHORT).show();<br>  &#125;<br></code></pre></td></tr></table></figure>
<h2 id="3-4-下拉刷新"><a href="#3-4-下拉刷新" class="headerlink" title="3.4 下拉刷新"></a>3.4 下拉刷新</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// SwipeRefreshLayout 下拉刷新</span><br><span class="hljs-meta">@Override</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onRefresh</span><span class="hljs-params">()</span> &#123;<br>    page = ((page == MAX_PAGE - <span class="hljs-number">1</span>) ? <span class="hljs-number">0</span> :  page + <span class="hljs-number">1</span>);<br>    list_lv.clear();<br>    list_lv.addAll(list_all.subList(page * PER_PAGE, (page+<span class="hljs-number">1</span>) * PER_PAGE - <span class="hljs-number">1</span>));<br>    System.out.println(list_lv.toString());<br>    adapter.notifyDataSetChanged();<br>    showPageInfo();<br>    refreshLayout.setRefreshing(<span class="hljs-literal">false</span>);<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="3-5-上拉加载"><a href="#3-5-上拉加载" class="headerlink" title="3.5 上拉加载"></a>3.5 上拉加载</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// ListView 上拉加载</span><br><span class="hljs-meta">@Override</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onScrollStateChanged</span><span class="hljs-params">(AbsListView absListView, <span class="hljs-type">int</span> i)</span> &#123;<br>    <span class="hljs-type">int</span> <span class="hljs-variable">last</span> <span class="hljs-operator">=</span>lv.getLastVisiblePosition();<br>    <span class="hljs-type">int</span> <span class="hljs-variable">first</span> <span class="hljs-operator">=</span> lv.getFirstVisiblePosition();<br>    <span class="hljs-type">int</span> <span class="hljs-variable">num</span> <span class="hljs-operator">=</span> lv.getCount();<br><br>    <span class="hljs-comment">// SCROLL_STATE_IDLE 表示 当前View没有滚动</span><br><br>    <span class="hljs-keyword">if</span>(last == num - <span class="hljs-number">1</span> &amp;&amp; SCROLL_STATE_IDLE == i)<br>        lv.addFooterView(foot);<br>    <span class="hljs-keyword">if</span>(num == PER_PAGE + <span class="hljs-number">1</span>)&#123;<br>        lv.removeFooterView(foot);<br>        onRefresh();<br>        lv.setSelection(<span class="hljs-number">0</span>);<br>    &#125;<br>&#125;<br><span class="hljs-comment">// ListView 上拉加载接口的另一个方法 没有用到 可以不管</span><br><span class="hljs-meta">@Override</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onScroll</span><span class="hljs-params">(AbsListView absListView, <span class="hljs-type">int</span> i, <span class="hljs-type">int</span> i1, <span class="hljs-type">int</span> i2)</span> &#123; &#125;<br></code></pre></td></tr></table></figure>

<h1 id="4-所有代码"><a href="#4-所有代码" class="headerlink" title="4. 所有代码"></a>4. 所有代码</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.example.test1;<br><br><span class="hljs-keyword">import</span> androidx.annotation.NonNull;<br><span class="hljs-keyword">import</span> androidx.annotation.Nullable;<br><span class="hljs-keyword">import</span> androidx.appcompat.app.AppCompatActivity;<br><span class="hljs-keyword">import</span> androidx.swiperefreshlayout.widget.SwipeRefreshLayout;<br><br><span class="hljs-keyword">import</span> android.os.Bundle;<br><span class="hljs-keyword">import</span> android.view.LayoutInflater;<br><span class="hljs-keyword">import</span> android.view.View;<br><span class="hljs-keyword">import</span> android.widget.AbsListView;<br><span class="hljs-keyword">import</span> android.widget.Adapter;<br><span class="hljs-keyword">import</span> android.widget.ArrayAdapter;<br><span class="hljs-keyword">import</span> android.widget.ListView;<br><span class="hljs-keyword">import</span> android.widget.TextView;<br><span class="hljs-keyword">import</span> android.widget.Toast;<br><br><span class="hljs-keyword">import</span> java.util.ArrayList;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">AppCompatActivity</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">SwipeRefreshLayout</span>.OnRefreshListener, AbsListView.OnScrollListener&#123;<br>    ArrayList&lt;String&gt; list_all;             <span class="hljs-comment">// 存储列表所有的测试数据</span><br>    ArrayList&lt;String&gt; list_lv;              <span class="hljs-comment">// 存储列表当前的数据</span><br>    ArrayAdapter&lt;String&gt; adapter;           <span class="hljs-comment">// ListView的适配器对象</span><br>    SwipeRefreshLayout refreshLayout;       <span class="hljs-comment">// 主界面刷新布局的对象</span><br>    ListView lv;                            <span class="hljs-comment">// 主界面列表对象</span><br>    View foot;                              <span class="hljs-comment">// 上拉加载底部的视图</span><br>    <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">MAX_PAGE</span> <span class="hljs-operator">=</span> <span class="hljs-number">5</span>;                 <span class="hljs-comment">// 最多的页数</span><br>    <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">PER_PAGE</span> <span class="hljs-operator">=</span> <span class="hljs-number">15</span>;                <span class="hljs-comment">// 每页的数据个数</span><br>    <span class="hljs-type">int</span> <span class="hljs-variable">page</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;                           <span class="hljs-comment">// 当前页数</span><br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onCreate</span><span class="hljs-params">(Bundle savedInstanceState)</span> &#123;<br>        <span class="hljs-built_in">super</span>.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);<br><br>        <span class="hljs-comment">// 1. 获取组件</span><br>        lv = findViewById(R.id.listview);<br>        refreshLayout = findViewById(R.id.refresh);<br><br>        <span class="hljs-comment">// 2. 产生列表框测试的数据</span><br>        list_all = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; PER_PAGE * MAX_PAGE; i++)<br>            list_all.add(String.format(<span class="hljs-string">&quot;Botton:%d&quot;</span>, i));<br>        list_lv = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;(list_all.subList(<span class="hljs-number">0</span>, PER_PAGE));<br><br>        <span class="hljs-comment">// 3. 设置 适配器 以及 视图</span><br>        adapter = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayAdapter</span>&lt;&gt;(<span class="hljs-built_in">this</span>, android.R.layout.simple_list_item_1, list_lv);<br>        foot = LayoutInflater.from(<span class="hljs-built_in">this</span>).inflate(R.layout.foot_view,<span class="hljs-literal">null</span>);<br>        lv.setAdapter(adapter);<br><br>        <span class="hljs-comment">// 4. 设置监听事件</span><br>        lv.setOnScrollListener(<span class="hljs-built_in">this</span>);               <span class="hljs-comment">// 下拉刷新</span><br>        refreshLayout.setOnRefreshListener(<span class="hljs-built_in">this</span>);   <span class="hljs-comment">// 上拉加载</span><br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">showPageInfo</span><span class="hljs-params">()</span>&#123;<br>        Toast.makeText(MainActivity.<span class="hljs-built_in">this</span>, String.format(<span class="hljs-string">&quot;当前是第%d页&quot;</span>,page), Toast.LENGTH_SHORT).show();<br>    &#125;<br>    <span class="hljs-comment">// SwipeRefreshLayout 下拉刷新</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onRefresh</span><span class="hljs-params">()</span> &#123;<br>        page = ((page == MAX_PAGE - <span class="hljs-number">1</span>) ? <span class="hljs-number">0</span> :  page + <span class="hljs-number">1</span>);<br>        list_lv.clear();<br>        list_lv.addAll(list_all.subList(page * PER_PAGE, (page+<span class="hljs-number">1</span>) * PER_PAGE - <span class="hljs-number">1</span>));<br>        System.out.println(list_lv.toString());<br>        adapter.notifyDataSetChanged();<br>        showPageInfo();<br>        refreshLayout.setRefreshing(<span class="hljs-literal">false</span>);<br>    &#125;<br><br>    <span class="hljs-comment">// ListView 上拉加载</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onScrollStateChanged</span><span class="hljs-params">(AbsListView absListView, <span class="hljs-type">int</span> i)</span> &#123;<br>        <span class="hljs-type">int</span> <span class="hljs-variable">last</span> <span class="hljs-operator">=</span>lv.getLastVisiblePosition();<br>        <span class="hljs-type">int</span> <span class="hljs-variable">first</span> <span class="hljs-operator">=</span> lv.getFirstVisiblePosition();<br>        <span class="hljs-type">int</span> <span class="hljs-variable">num</span> <span class="hljs-operator">=</span> lv.getCount();<br><br>        <span class="hljs-comment">// SCROLL_STATE_IDLE 表示 当前View没有滚动</span><br><br>        <span class="hljs-keyword">if</span>(last == num - <span class="hljs-number">1</span> &amp;&amp; SCROLL_STATE_IDLE == i)<br>            lv.addFooterView(foot);<br>        <span class="hljs-keyword">if</span>(num == PER_PAGE + <span class="hljs-number">1</span>)&#123;<br>            lv.removeFooterView(foot);<br>            onRefresh();<br>            lv.setSelection(<span class="hljs-number">0</span>);<br>        &#125;<br>    &#125;<br>    <span class="hljs-comment">// ListView 上拉加载接口的另一个方法 没有用到 可以不管</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">onScroll</span><span class="hljs-params">(AbsListView absListView, <span class="hljs-type">int</span> i, <span class="hljs-type">int</span> i1, <span class="hljs-type">int</span> i2)</span> &#123; &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%AE%89%E5%8D%93/" class="category-chain-item">安卓</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Android/">#Android</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView</div>
      <div>http://example.com/2021/11/21/Android _ 同时实现上拉刷新和下拉加载 _ 基于SwipeRefreshLayout 和 ListView/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年11月21日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/11/22/Java%E9%9B%86%E5%90%88%E7%B3%BB%E5%88%97%EF%BC%88%E4%B8%80%EF%BC%89_%20PriorityQueue%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%20_%20%E7%BB%BC%E5%90%88%E8%BF%90%E7%94%A8%20_%20%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3/" title="Java集合系列1_ PriorityQueue优先队列 _ 综合运用 _ 深入理解">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Java集合系列1_ PriorityQueue优先队列 _ 综合运用 _ 深入理解</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/11/21/Java%20_%20Comparable%E6%8E%A5%E5%8F%A3%E4%B8%8EComparator%E6%8E%A5%E5%8F%A3%E7%9A%84%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%20_%20%E6%9C%89%E5%85%B3%E6%8E%92%E5%BA%8F%E7%9A%84%E9%83%BD%E4%BC%9A%E7%94%A8%E5%88%B0/" title="Java _ Comparable接口与Comparator接口的深入理解 _ 有关排序的都会用到">
                        <span class="hidden-mobile">Java _ Comparable接口与Comparator接口的深入理解 _ 有关排序的都会用到</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
